package com.lz.football.module.playerCenter.tabBtn
{
	import com.lz.football.module.base.IComponent;
	
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	import lz.controls.LButton;
	
	public class TabBtnMenuPanel extends Sprite implements IComponent
	{
		/**
		 * 
		 */
		private var symbolSkin:MovieClip;
		/**
		 * 
		 */
		private var tabBtn_1:LButton;
		private var tabBtn_2:LButton;
		private var tabBtn_3:LButton;
		private var tabBtn_4:LButton;
		private var tabBtn_5:LButton;
		private var tabBtn_6:LButton;
		private var tabBtn_7:LButton;
		public var selectBtn 	:LButton;//选择的btn
		public var selectType 	:int = 0;//选择类型
		public function TabBtnMenuPanel()
		{
			super();
		}
		
		public function initUI(view:Object=null):void
		{
			symbolSkin = view as MovieClip;
			
			
			
			
		}
		public function init(view:MovieClip,$num:int):void
		{
			symbolSkin = view;
			for(var i:int = 0;i < $num;i++)
			{
				this["tabBtn_"+ (i + 1)] = new LButton(symbolSkin["tabBtn_"+ (i + 1)]);
				this["tabBtn_"+ (i + 1)].enable = true;
				this["tabBtn_"+ (i + 1)].addEventListener(MouseEvent.CLICK,onClickHandler);
			}
		}
		
		
		public function addEvtListener():void
		{
		}
		/**
		 * 设置选中状态
		 * @param $type
		 * 
		 */
		public function setSelectStatus($type:int):void
		{
			if(selectBtn)
			{
				selectBtn.enable = true;
				selectBtn.setStatus(LButton.UP);
			}
			selectType = $type;
			switch($type)
			{
				case TabBtnConst.ONE_CONST:
					selectTabButton(tabBtn_1);
					break;
				case TabBtnConst.TWO_CONST:
					selectTabButton(tabBtn_2);
					break;
				case TabBtnConst.THREE_CONST:
					selectTabButton(tabBtn_3);
					break;
				case TabBtnConst.FOUR_CONST:
					selectTabButton(tabBtn_4);
					break;
				case TabBtnConst.FIVE_CONST:
					selectTabButton(tabBtn_5);
					break;
				case TabBtnConst.SIX_CONST:
					selectTabButton(tabBtn_6);
					break;
				case TabBtnConst.SEVEN_CONST:
					selectTabButton(tabBtn_7);
					break;
				//				case TabBtnConst.EIGHT_CONST:
				//					selectTabButton(_eightBtn);
			}
		}
		/**
		 * 
		 * @param event
		 * 
		 */
		private function onClickHandler(event:MouseEvent):void
		{
			if(selectBtn)
			{
				selectBtn.enable = true;
				selectBtn.setStatus(LButton.UP);
			}
			selectTabButton( event.target as LButton ); 
			switch(selectBtn)
			{
				case tabBtn_1:
					selectType = TabBtnConst.ONE_CONST;
					break;
				case tabBtn_2:
					selectType = TabBtnConst.TWO_CONST;
					break;
				case tabBtn_3:
					selectType = TabBtnConst.THREE_CONST;
					break;
				case tabBtn_4:
					selectType = TabBtnConst.FOUR_CONST;
					break;
				case tabBtn_5:
					selectType = TabBtnConst.FIVE_CONST;
					break;
				case tabBtn_6:
					selectType = TabBtnConst.SIX_CONST;
					break;
				case tabBtn_7:
					selectType = TabBtnConst.SEVEN_CONST;
					break;
				
			}
			this.dispatchEvent(new Event(Event.CHANGE));
		}
		/**
		 *选择某个tab button 
		 * @param lBtn
		 * 
		 */		
		public function selectTabButton(lBtn :LButton):void
		{
			selectBtn = lBtn;
			if(selectBtn)
			{
				selectBtn.enable = false;
				selectBtn.setStatus(LButton.SELECT);
			}
		}
		public function removeEvtListener():void
		{
			if(tabBtn_1 != null)tabBtn_1.removeEventListener(MouseEvent.CLICK,onClickHandler);
			if(tabBtn_2 != null)tabBtn_2.removeEventListener(MouseEvent.CLICK,onClickHandler);
			if(tabBtn_3 != null)tabBtn_3.removeEventListener(MouseEvent.CLICK,onClickHandler);
			if(tabBtn_4 != null)tabBtn_4.removeEventListener(MouseEvent.CLICK,onClickHandler);
			if(tabBtn_5 != null)tabBtn_5.removeEventListener(MouseEvent.CLICK,onClickHandler);
			if(tabBtn_6 != null)tabBtn_6.removeEventListener(MouseEvent.CLICK,onClickHandler);
			if(tabBtn_7 != null)tabBtn_7.removeEventListener(MouseEvent.CLICK,onClickHandler);
		}
		
		public function destroyView():void
		{
			removeEvtListener();
			if(tabBtn_1 != null)tabBtn_1.enable = false;
			if(tabBtn_2 != null)tabBtn_2.enable = false;
			if(tabBtn_3 != null)tabBtn_3.enable = false;
			if(tabBtn_4 != null)tabBtn_4.enable = false;
			if(tabBtn_5 != null)tabBtn_5.enable = false;
			if(tabBtn_6 != null)tabBtn_6.enable = false;
		}
	}
}